package com.wyh.threadlocal;

public class Main {
    public static ThreadLocal<String> threadLocal = new ThreadLocal<>();

    //带有默认值
    public static ThreadLocal<String> threadLocal1 = ThreadLocal.withInitial(()->"threadLocal......");

    public static void main(String[] args) {
        Thread thread1 = new Thread(()->{
            threadLocal.set("thread1......");
            System.out.println(threadLocal.get());
            System.out.println(threadLocal1.get());
        });

        Thread thread2 = new Thread(()->{
            threadLocal.set("thread2......");
            System.out.println(threadLocal.get());
            threadLocal.remove();
            System.out.println(threadLocal.get());
        });

        thread1.start();
        thread2.start();
    }
}
